package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.JkUser;
import com.ruoyi.service.IJkUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息Controller
 *
 * @author ruoyi
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/user/info")
public class JkUserController extends BaseController
{
    @Autowired
    private IJkUserService jkUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('user:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(JkUser jkUser)
    {
        startPage();
        List<JkUser> list = jkUserService.selectJkUserList(jkUser);
        return getDataTable(list);
    }

    /**
     * 查询全部用户信息
     */
    @PreAuthorize("@ss.hasPermi('user:info:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(JkUser jkUser)
    {
        List<JkUser> list = jkUserService.selectJkUserList(jkUser);
        return AjaxResult.success(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('user:info:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JkUser jkUser)
    {
        List<JkUser> list = jkUserService.selectJkUserList(jkUser);
        ExcelUtil<JkUser> util = new ExcelUtil<JkUser>(JkUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jkUserService.selectJkUserById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('user:info:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JkUser jkUser)
    {
        return toAjax(jkUserService.insertJkUser(jkUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('user:info:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JkUser jkUser)
    {
        return toAjax(jkUserService.updateJkUser(jkUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('user:info:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jkUserService.deleteJkUserByIds(ids));
    }
}
